<?php

/**
 * Admin module bootstrap
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @package   Mz
 * @category  modules
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: Bootstrap.php 38 2009-02-18 17:12:39Z monzee $
 */
class Admin_Bootstrap extends Mz_Module_Bootstrap
{
    protected $_helper;

    public function init()
    {
        // Set up the layout
        if (null === Zend_Layout::getMvcInstance()) {
            Zend_Layout::startMvc(array(
                'layout' => 'default',
                'layoutPath' => $this->pathTo('layouts'),
            ));
        }

        // turn this off if you're not editing the templates anyway
        $this->_registerIfNone('Yano_Template');

        $this->_helper = new Admin_AccessManager();
        Zend_Controller_Action_HelperBroker::addHelper($this->_helper);

        Zend_Controller_Action_HelperBroker::addPrefix('Mz_Helper_Action');

        // initialize doctrine if present
        if (class_exists('Doctrine', true)) {
            $manager = Doctrine_Manager::getInstance();

            $cache = $manager->openConnection('sqlite::memory:');
            $queryCache = new Doctrine_Cache_Db(array(
                'connection' => $cache,
                'tableName' => 'query_cache',));
            $queryCache->createTable();
            $manager->setAttribute(Doctrine::ATTR_QUERY_CACHE, $queryCache);

            $dsn = 'sqlite:' . $this->pathTo('admin.db.sqlite');
            $manager->openConnection($dsn);

            $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
            $manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
            $manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);
            $manager->setAttribute(Doctrine::ATTR_MODEL_LOADING,
                Doctrine::MODEL_LOADING_CONSERVATIVE);
            $manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_TABLES);
        }
    }

    public function getAccessManager()
    {
        return $this->_helper;
    }

}
